//
//  WidgetsSubViewController.swift
//  TimMusic
//
//  Created by nkl on 2024/10/11.
//

import Foundation
import SwiftUI

class WidgetsSubViewController: BasicViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .clear
        var contentView = WidgetContentView()
        contentView.didSelectedItem = { [weak self] model in
            guard let self = self else {
                return
            }
            let vc = WidgetPreviewController()
            vc.modalPresentationStyle = .overFullScreen
            vc.widgetModel = model
            self.present(vc, animated: true)
        }
        let hostingController = UIHostingController(rootView: contentView)
        hostingController.view.backgroundColor = .clear

        // 添加 Hosting Controller 的视图到当前视图控制器
        addChild(hostingController)
        view.addSubview(hostingController.view)

        hostingController.view.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }

        hostingController.didMove(toParent: self)
    }
}
